package com.lancoo.cvas.pojo.common;

import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

/**
 * @ClassName CollComparatorUtil
 * @Description 集合比较工具类
 * @Author quin
 * @Date 2023/3/31 11:00
 */
@Component
public class CollComparatorUtil<T> {

    //获取新增的元素
    public List<T> getAdded(List<T> oldList, List<T> newList) {
        List<T> added = new ArrayList<>(newList);
        added.removeAll(oldList);
        return added;
    }

    //获取修改的元素
    public List<T> getModified(List<T> oldList, List<T> newList) {
        List<T> modified = new ArrayList<>();
        for (T element : oldList) {
            if (newList.contains(element)) {
                modified.add(element);
            }
        }
        return modified;
    }

    //获取删除的元素
    public List<T> getDeleted(List<T> oldList, List<T> newList) {
        List<T> deleted = new ArrayList<>(oldList);
        deleted.removeAll(newList);
        return deleted;
    }
}
